<template>
  <view v-if="!isLoading">
    <view class="lists" v-if="!isEmpty">
      <view v-for="(item,index) in lists">
        <teacher-row :item="item"></teacher-row>
      </view>
    </view>
    <view v-else>
      <xy-empty text="暂无数据" />
    </view>
  </view>
</template>

<script>
import { mapState } from 'vuex';
import xyEmpty from '@/components/xy-empty';
import teacherRow from "@/components/teacher/row.vue"
export default {
  components: {
    xyEmpty,
    teacherRow
  },
  data() {
    return {
      isLoading:true,
      isEmpty: true,
      lists: [],
      currentPage: 1,
      lastPage: 1,
    }
  },
  computed: {
    ...mapState(['common'])
  },
  async onLoad(options) {
    uni.setNavigationBarTitle({
      title : this.common.auditConfig.pages_user_collect
    })
    if(options?.type){
      this.type = options.type;
    }
    this.loadData();
  },
  onPullDownRefresh() {
    this.currentPage = 1;
    this.lists = [];
    this.loadData();
  },
  onReachBottom() {
    if(this.currentPage < this.lastPage) {
      this.currentPage += 1;
      this.loadData();
    }
  },
  methods: {
    async loadData(){

      this.$api.postBase({
        url: '/collect/lists',
        loadingTip:'加载中...',
        data: {
          page: this.currentPage,
        },
        success: res => {
          uni.stopPullDownRefresh();
          this.isLoading = false;
          this.lists = [...this.lists, ...res.data];
          this.isEmpty = !this.lists.length;
          this.currentPage = res.current_page;
          this.lastPage = res.last_page;
        }
      });
    },

  }
}
</script>

<style scoped lang="scss">
.lists{
  padding: 20rpx;
}
</style>